from .celery import app



# 案例：django异步更新缓存
from home.models import Banner
from django.conf import settings
from django.core.cache import cache
from home.serializers import BannerSerializers
@app.task
def update_banner_cache():
    banner_query = Banner.objects.filter(is_delelte=False, is_show=True).order_by('-order').all()[:settings.MAX_COUNT]
    banner_data = BannerSerializers(banner_query, many=True).data
    for banner in banner_data:
        banner['image'] = "%s%s" % (settings.BASE_URL, banner.get('image'))
    cache.set('banner_cache', banner_data)
    return True



